package com.cloud.drore.eboss.operation.controller;


import com.cloud.drore.eboos.common.base.ResultMessage;


import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.login.user.Anon;
import com.cloud.drore.eboss.operation.entity.Merchant;
import com.cloud.drore.eboss.operation.entity.POIOperation;
import com.cloud.drore.eboss.operation.entity.po.POIOperationPo;
import com.cloud.drore.eboss.operation.entity.po.POIPo;
import com.cloud.drore.eboss.operation.entity.vo.DictionaryPOIVo;
import com.cloud.drore.eboss.operation.service.impl.POIServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: poi接口<br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/6 0006 下午 5:23 <br>
 * @Author: <a href="410508961@qq.com">夏凯</a>
 */
@RestController
@RequestMapping("/poi")
@Api(value = "/信息点（POIOperation）接口", description = "POI管理接口-夏凯")
public class POIController {
    @Resource
    POIServiceImpl POIServiceImpl;


    @ApiOperation(value = "保存信息")
    @PostMapping(value = "/save")
    public ResultMessage save(@RequestBody @Validated POIOperation po) throws BusinessException {
        //判断POIName是否重名
        Boolean aBoolean = POIServiceImpl.judgePoiName(po.getPoiName());
        if (aBoolean == false) {
            throw new BusinessException("POI名称不能重复！");
        }
        POIServiceImpl.insertPoi(po);
        ResultMessage resultMessage = new ResultMessage();
        resultMessage.setId(po.getId() + "");
        return resultMessage;
    }

    @ApiOperation(value = "更新信息")
    @PutMapping(value = "/update")
    public ResultMessage update(@RequestBody @Validated POIOperationPo POIOperation) throws BusinessException {

        if (POIServiceImpl.poiUpdate(POIOperation) != 1) {
            throw new BusinessException("POI更新信息失败！");
        }
        ResultMessage resultMessage = new ResultMessage();
        resultMessage.setId(POIOperation.getId() + "");
        return resultMessage;
    }

    @ApiOperation(value = "删除信息")
    @DeleteMapping(value = "/delete/{id}")
    public ResultMessage<POIOperation> delete(@PathVariable("id") Long id) {
        return new ResultMessage(POIServiceImpl.deleteByPrimaryKey(id));
    }

    @ApiOperation(value = "根据id查找poi")
    @GetMapping(value = "/getPOIList/{id}")
    public ResultMessage<POIOperation> getPOIList(@PathVariable("id") Long id) {
        return new ResultMessage(POIServiceImpl.selectByPrimaryKey(id));
    }

    @Anon
    @ApiOperation(value = "根据id查找poi分销服务远程调用")
    @GetMapping(value = "/getPOIListForDealer/{id}")
    public ResultMessage<POIOperation> getPOIListForDealer(@PathVariable("id") Long id) {
        return new ResultMessage(POIServiceImpl.selectByPrimaryKey(id));
    }

    @ApiOperation(value = "查询所有POI集合的接口不分页，运营商、加载poi首页的时候使用")
    @GetMapping(value = "findPOI")
    public ResultMessage<POIOperation> findPOI() {
        return POIServiceImpl.findByName();
    }

    @Anon
    @ApiOperation(value = "分销服务远程调用")
    @GetMapping(value = "findPOIForDealer")
    public ResultMessage<POIOperation> findPOIForDealer() {
        return POIServiceImpl.findByName();
    }

    @ApiOperation(value = "初始化加载商户信息列表")
    @GetMapping(value = "initMerchantList")
    public ResultMessage<Merchant> initMerchantList() {
        return POIServiceImpl.findMerchantList();
    }


    @ApiOperation(value = "根据POI查POI列表")
    @PostMapping(value = "/selectPOIByType")
    public ResultMessage<POIOperation> selectPOIByType(@RequestBody @Valid POIPo POIOperation) throws BusinessException {
        return new ResultMessage(POIServiceImpl.selectPoiListByType(POIOperation));
    }

    @ApiOperation(value = "初始化POI类型")
    @GetMapping(value = "init")
    public ResultMessage<DictionaryPOIVo> init() {
        return POIServiceImpl.findInitDictionary();
    }

}
